package cn.funeralobjects.upms.api;

import cn.funeralobjects.common.web.api.*;
import cn.funeralobjects.upm.web.model.MUser;
import cn.funeralobjects.upm.web.model.VUser;
import cn.funeralobjects.upm.web.model.VUserCertificate;
import cn.funeralobjects.upm.web.model.VUserSecret;
import cn.funeralobjects.upms.enums.UserCertificateType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * 用户API接口
 *
 * @author FuneralObjects
 * Create date: 2020/4/30 3:11 PM
 */
@Validated
public interface UserApi extends
        CommonModifyRestApi<VUser, MUser, Integer>,
        RestCodeApi<VUser, Integer>,
        RestCommitApi<Integer>,
        RestEnableApi<VUser, Integer>,
        RestEntityApi<VUser, Integer> {


    @PostMapping("/{userId}/cert")
    Mono<VUserCertificate> addUserCert(@PathVariable("userId") Integer userId,
                                       @RequestParam("code") String code,
                                       @RequestParam("type") UserCertificateType type,
                                       @RequestParam("cert") String cert);

//    @PostMapping("/code-{userCode}/cert")
//    Mono<VUserCertificate> addUserCert(@PathVariable("userCode") String userCode,
//                                       @RequestParam("code") String code,
//                                       @RequestParam("type") UserCertificateType type,
//                                       @RequestParam("cert") String cert);

    @GetMapping("/{userId}/cert")
    Mono<List<VUserCertificate>> getUserCerts(@PathVariable Integer userId);

    @PatchMapping("/{userId}/secret")
    Mono<Void> updateSecret(@PathVariable("userId") Integer userId,
                            @RequestParam("secret") String secret);

//    @PatchMapping("/code-{userCode}/secret")
//    Mono<Void> updateSecret(@PathVariable("userCode") String userCode,
//                            @RequestParam("secret") String secret);

    @GetMapping("/code-{userCode}")
    Mono<VUserSecret> getSecret(@PathVariable("userCode") String userCode);

    @GetMapping("/cert")
    Mono<VUserSecret> getSecret(@RequestParam("cert") String cert, @RequestParam("type") UserCertificateType type);
}
